{
  LX Tool module

  Based on modo's SDK lxtool.h which is:

  Copyright (c) 2008-2012 Luxology LLC

  Permission is hereby granted, free of charge, to any person obtaining a
  copy of this software and associated documentation files (the "Software"),
  to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense,
  and/or sell copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.   Except as contained
  in this notice, the name(s) of the above copyright holders shall not be
  used in advertising or otherwise to promote the sale, use or other dealings
  in this Software without prior written authorization.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
}

{
  Copyright (c) 2012, David Ballesteros and Jameel Halabi

  This unit is part of the BLAISEmodo wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}


unit Lx_Tool;

{$mode objfpc}{$H+}

interface

uses
  Lx_Result, Lx_Server, Lx_VMath;

const
  LXa_TOOL                    = 'tool';

  LXf_SHOULDBE_ATTR           = 1;

  LXf_PATHKNOT_BROKEN         = 1;

  LXf_PARTGEN_CONNECT         = $01;
  LXf_PARTGEN_ABSSIZE         = $02;
  LXf_PARTGEN_MIRROR          = $04;

  LXiTVXFMf_OFFSET            = 1;
  LXiTVXFMf_MATRIX            = 2;
  LXiTVXFMf_INVERSE           = 4;
  LXiTVXFMf_USEFUL            = LXiTVXFMf_OFFSET or LXiTVXFMf_MATRIX;

  LXs_ORD_CONT                = '\x38';
  LXs_ORD_SNAP                = '\x40';
  LXs_ORD_CONS                = '\x41';
  LXs_ORD_ACEN                = '\x60';
  LXs_ORD_AXIS                = '\x70';
  LXs_ORD_PATH                = '\x80';
  LXs_ORD_WGHT                = '\x90';
  LXs_ORD_PINK                = '\xB0';
  LXs_ORD_NOZL                = '\xB1';
  LXs_ORD_BRSH                = '\xB2';
  LXs_ORD_PTCL                = '\xC0';
  LXs_ORD_SIDE                = '\xD0';
  LXs_ORD_EFFR                = '\xD8';
  LXs_ORD_ACTR                = '\xF0';
  LXs_ORD_POST                = '\xF1';

  LXsCATEGORY_TOOL            = 'tool';

  LXsP_TOOL_SUBJECT           = 'tool.subject'      ;
  LXsP_TOOL_ACTCENTER         = 'tool.actionCenter' ;
  LXsP_TOOL_AXIS              = 'tool.axis'         ;
  LXsP_TOOL_XFRM              = 'tool.xfrm'         ;
  LXsP_TOOL_FALLOFF           = 'tool.falloff'      ;
  LXsP_TOOL_SYMMETRY          = 'tool.symmetry'     ;
  LXsP_TOOL_TEXTURE           = 'tool.texture'      ;
  LXsP_TOOL_ELTCENTER         = 'tool.eltCenter'    ;
  LXsP_TOOL_ELTAXIS           = 'tool.eltAxis'      ;
  LXsP_TOOL_PATHGEN           = 'tool.pathGenerator';
  LXsP_TOOL_PARTGEN           = 'tool.partGenerator';
  LXsP_TOOL_CONTENT           = 'tool.content'      ;

  LXu_TOOL                    = '{12E79F81-565E-11D7-A4CF-000A95765C9E}';
  LXu_ATTRSEQUENCE            = '{F54FEF16-223F-439D-8593-6F350783993E}';
  LXu_FALLOFFPACKET           = '{D0F8CF5D-1BB5-4002-810B-0E7EF34B7867}';
  LXu_SYMMETRYPACKET          = '{F13F6933-1289-4EFC-9CE1-D5C4F13EE7D8}';
  LXu_TEXTUREPACKET           = '{851271E5-F4F4-444D-A87A-563B9E1E6EFB}';
  LXu_ELEMENTAXISPACKET       = '{292A47BF-3CF5-492D-AAFD-AE761092A782}';
  LXu_ELEMENTCENTERPACKET     = '{5221C415-073A-4610-BCB6-F820F8D7F6D0}';
  LXu_BAGGENERATOR            = '{9A368FAA-7576-42B9-9B6A-C2F8D34612F0}';
  LXu_PATHSTEP                = '{B9F58563-FBA0-4CA2-866B-1DD64174A277}';
  LXu_PATHGENERATORPACKET     = '{AE70D946-8A9A-4A72-95EC-BFF856391D22}';
  LXu_PARTICLEGENERATORPACKET = '{5CDF5B58-46BF-4D78-8652-659E87E19C4B}';

  LXv_PATHGEN_DIV_COARSE      = 0.105;
  LXv_PATHGEN_DIV_MEDIUM      = 0.087;
  LXv_PATHGEN_DIV_FINE        = 0.052;

type
  PathWalkerFunc = procedure(Data : Pointer  ;
                             T    : Double   ;
                             Pos  : LXtVector);

  // Start of types from lxmeshold.h
  PLXtMesh = ^LXtMesh  ;
  LXtMesh  = record end;

  PLXtPnt     = Pointer;
  PLXtPol     = Pointer;
  PLXtOldEdge = Pointer;
  PLXtVMap    = Pointer;
  // End of types from lxmeshold.h

  PLXpToolSubject = ^LXpToolSubject;
  LXpToolSubject  = record
    Mesh  : PLXtMesh;
    VMap  : PLXtVMap;
    &Type : LXtID4  ;
    Base  : PLXtMesh;
  end;

  PLXpToolActionCenter = ^LXpToolActionCenter;
  LXpToolActionCenter  = record
    V : LXtVector;
  end;

  PLXpToolAxis = ^LXpToolAxis;
  LXpToolAxis  = record
    Axis    : LXtVector;
    Up      : LXtVector;
    Right   : LXtVector;
    M, MInv : LXtMatrix;
    AxIndex : Integer  ;
    &Type   : Integer  ;
  end;

  PLXpToolXfrm = ^LXpToolXfrm;
  LXpToolXfrm  = record
    V          : LXtVector;
    M          : LXtMatrix;
    MInv       : LXtMatrix;
    Flags      : Integer  ;
    Handedness : Integer  ;
    Marks      : UInt32   ;
  end;

  PLXtPathKnot = ^LXtPathKnot;
  LXtPathKnot  = record
    Position   : LXtFVector;
    TanIn      : LXtFVector;
    TanOut     : LXtFVector;
    Flags      : Integer   ;
    ClientData : Pointer   ;
    Bank       : Double    ;
  end;

  PLXtPGenParticle = ^LXtPGenParticle;
  LXtPGenParticle  = record
    Position    : LXtFVector;
    Scale       : LXtFVector;
    Orientation : LXtMatrix ;
    Flags       : Integer   ;
  end;

  PLXpToolContent = ^LXpToolContent;
  LXpToolContent  = record
    Path    : PChar    ;
    &Type   : PChar    ;
    Scale   : Double   ;
    Axis    : LXtVector;
    Offset  : LXtVector;
    AxIndex : Integer  ;
    Flags   : Integer  ;
    Data    : Pointer  ;
  end;

  ILxTool = interface
  [LXu_TOOL]
    procedure Reset                               ;
    procedure Evaluate         (VtS   : IUnknown) ;
    function  VectorType                          : Pointer ;
    function  Order                               : PChar   ;
    function  Task                                : LXtID4  ;
    function  Sequence         (Seq   : IUnknown) : LxResult;
    function  ShouldBeAttribute(Task_ : LXtID4  ) : Integer ;
  end;

  ILxAttrSequence = interface
  [LXu_ATTRSEQUENCE]
    function Integer   (const Name  : PChar   ;
                              Value : Integer ) : LxResult;
    function Float     (const Name  : PChar   ;
                              Value : Double  ) : LxResult;
    function AttrString(const Name  : PChar   ;
                        const Value : PChar   ) : LxResult;
    function Value     (const Name  : PChar   ;
                              Value : IUnknown) : LxResult;
  end;

  ILxFalloffPacket = interface
  [LXu_FALLOFFPACKET]
    function Evaluate(Pos : LXtFVector;
                      VRX : PLXtPnt   ) : Double;
    function Screen  (VTS : IUnknown  ;
                      X   : Integer   ;
      		      Y   : Integer   ) : Double;
  end;

  ILxSymmetryPacket = interface
  [LXu_SYMMETRYPACKET]
    function Active                               : Integer    ;
    function Axis    (      AxVec  : LXtFVector ;
                            Offset : PSingle    ) : Integer    ;
    function Point   (      Mesh   : PLXtMesh   ;
                            VRX    : PLXtPnt    ) : PLXtPnt    ;
    function Polygon (      Mesh   : PLXtMesh   ;
                            Pol    : PLXtPol    ) : PLXtPol    ;
    function Edge    (      Mesh   : PLXtMesh   ;
                            Edge   : PLXtOldEdge) : PLXtOldEdge;
    function Position(const Pos    : LXtFVector ;
                            SV     : LXtFVector ) : Integer    ;
  end;

  ILxTexturePacket = interface
  [LXu_TEXTUREPACKET]
    function Evaluate(Pos     : LXtFVector;
                      VRX     : PLXtPnt   ;
                      Pol     : PLXtPol   ;
                      Context : Integer   ;
                      Res     : PDouble   ) : LxResult;
  end;

  ILxElementAxisPacket = interface
  [LXu_ELEMENTAXISPACKET]
    function Axis(VRX  : PLXtPnt   ;
                  Axis : LXtFVector;
                  M    : LXtMatrix ;
                  MInv : LXtMatrix ) : LxResult;
  end;

  ILxElementCenterPacket = interface
  [LXu_ELEMENTCENTERPACKET]
    function Center(VRX    : PLXtPnt   ;
                    Center : LXtFVector) : LxResult;
  end;

  ILxPathGeneratorPacket = interface
  [LXu_PATHGENERATORPACKET]
    function Value      (VTS      : IUnknown    ;
                         T        : Double      ;
                         Pos      : LXtVector   ) : LxResult;
    function Length     (VTS      : IUnknown    ;
                         T0       : Double      ;
                         T1       : Double      ) : Double  ;
    function Tangent    (VTS      : IUnknown    ;
                         T        : Double      ;
                         Tan      : PDouble     ) : LxResult;
    function Source     (VTS      : IUnknown    ) : PLXtPol ;
    function Count      (VTS      : IUnknown    ) : Integer ;
    function Knot       (VTS      : IUnknown    ;
                         Index    : Integer     ;
                         Knot     : PLXtPathKnot) : LxResult;
    function Current    (VTS      : IUnknown    ) : Integer ;
    function KnotDataSet(Gen      : IUnknown    ) : LxResult;
    function Walk       (VTS      : IUnknown    ;
                         PathStep : IUnknown    ;
                         Angle    : Double      ;
                         TI       : Double      ;
                         TF       : Double      ) : Integer ;
    function Bank       (VTS      : IUnknown    ;
                         T        : Double      ) : Double  ;
  end;

  ILxBagGenerator = interface
  [LXu_BAGGENERATOR]
    function  Generate(Data    : Pointer;
                       CloneMe : Pointer) : Pointer;
    procedure Dispose (Data    : Pointer) ;
  end;

  ILxPathStep = interface
  [LXu_PATHSTEP]
    procedure Setup                    ;
    function  Step   (T   : Double   ;
                      Pos : LXtVector) : Integer;
    procedure CleanUp                  ;
  end;

  ILxParticleGeneratorPacket = interface
  [LXu_PARTICLEGENERATORPACKET]
    function Count             (      VTS   : IUnknown        ) : Integer ;


    function Particle          (      VTS   : IUnknown        ;
                                      Index : Integer         ;
                                      Part  : LXtPGenParticle ) : LxResult;
    function InitialParticleSet(const Part  : PLXtPGenParticle) : LxResult;
    function HintBoxSet        (const Box   : PLXtBBox        ;
                                      Part  : PLXtPGenParticle) : LxResult;
  end;

  { TLxTool }

  TLxTool = class(TLxServer, ILxTool)
    class
    function  GetServerType                       : TGuid   ; override;

    procedure Reset                               ;           virtual ;
    procedure Evaluate         (VtS   : IUnknown) ;           virtual ;
    function  VectorType                          : Pointer ; virtual ;
    function  Order                               : PChar   ; virtual ;
    function  Task                                : LXtID4  ; virtual ;
    function  Sequence         (Seq   : IUnknown) : LxResult; virtual ;
    function  ShouldBeAttribute(Task_ : LXtID4  ) : Integer ; virtual ;
  end;

function LXi_TASK_SNAP : LXtID4;
function LXi_TASK_ACEN : LXtID4;
function LXi_TASK_AXIS : LXtID4;
function LXi_TASK_WGHT : LXtID4;
function LXi_TASK_CONS : LXtID4;
function LXi_TASK_ACTR : LXtID4;
function LXi_TASK_SIDE : LXtID4;
function LXi_TASK_PATH : LXtID4;
function LXi_TASK_PTCL : LXtID4;
function LXi_TASK_EFFR : LXtID4;
function LXi_TASK_BRSH : LXtID4;
function LXi_TASK_NOZL : LXtID4;
function LXi_TASK_PINK : LXtID4;
function LXi_TASK_CONT : LXtID4;
function LXi_TASK_POST : LXtID4;

implementation

function LXi_TASK_SNAP : LXtID4; inline;
begin
  Result := LXxID4('S','N','A','P');
end;
function LXi_TASK_ACEN : LXtID4; inline;
begin
  Result := LXxID4('A','C','E','N');
end;
function LXi_TASK_AXIS : LXtID4; inline;
begin
  Result := LXxID4('A','X','I','S')
end;
function LXi_TASK_WGHT : LXtID4; inline;
begin
  Result := LXxID4('W','G','H','T');
end;
function LXi_TASK_CONS : LXtID4; inline;
begin
  Result := LXxID4('C','O','N','S');
end;
function LXi_TASK_ACTR : LXtID4; inline;
begin
  Result := LXxID4('A','C','T','R');
end;
function LXi_TASK_SIDE : LXtID4; inline;
begin
  Result := LXxID4('S','I','D','E');
end;
function LXi_TASK_PATH : LXtID4; inline;
begin
  Result := LXxID4('P','A','T','H');
end;
function LXi_TASK_PTCL : LXtID4; inline;
begin
  Result := LXxID4('P','T','C','L');
end;
function LXi_TASK_EFFR : LXtID4; inline;
begin
  Result := LXxID4('E','F','F','R');
end;
function LXi_TASK_BRSH : LXtID4; inline;
begin
  Result := LXxID4('B','R','S','H');
end;
function LXi_TASK_NOZL : LXtID4; inline;
begin
  Result := LXxID4('N','O','Z','L');
end;
function LXi_TASK_PINK : LXtID4; inline;
begin
  Result := LXxID4('P','I','N','K');
end;
function LXi_TASK_CONT : LXtID4; inline;
begin
  Result := LXxID4('C','O','N','T');
end;
function LXi_TASK_POST : LXtID4; inline;
begin
  Result := LXxID4('P','O','S','T');
end;

{ TLxTool }

class function TLxTool.GetServerType: TGuid;
begin
  Result := ILxTool;
end;

procedure TLxTool.Reset;
begin
end;

procedure TLxTool.Evaluate(VtS: IUnknown);
begin
end;

function TLxTool.VectorType: Pointer;
begin
end;

function TLxTool.Order: PChar;
begin
  Result := nil;
end;

function TLxTool.Task: LXtID4;
begin
  Result := 0;
end;

function TLxTool.Sequence(Seq: IUnknown): LxResult;
begin
  Result := LXe_NOTIMPL;
end;

function TLxTool.ShouldBeAttribute(Task_: LXtID4): Integer;
begin
  Result := 0;
end;

end.

